#include <bits/stdc++.h>

using namespace std;
struct node{
    int val;
    struct node *left,*right;
};
int in[10010],pre[10010],pos[10010],M,N;

unordered_map<int,bool> isValid;

int main(){
    freopen("../test.txt","r",stdin);
    cin>>M>>N;


    for(int i=1;i<=N;i++) {
        cin>>in[i];
        pos[in[i]] = i;
        isValid[in[i]] = true;
    }
    for(int i=1;i<=N;i++) {
        cin>>pre[i];
        isValid[pre[i]] = true;
    }

    int a,b;
    while(M--){
        cin>>a>>b;
        if(!isValid[a] && !isValid[b]) {
            printf("ERROR: %d and %d are not found.\n",a,b);
            continue;
        }else if(!isValid[a]){
            printf("ERROR: %d is not found.\n",a);
            continue;
        }else if(!isValid[b]){
            printf("ERROR: %d is not found.\n",b);
            continue;
        }

//        if(root->val!=a && root->val!=b){
//            printf("LCA of %d and %d is %d.\n",a,b,root->val);
//        }else{
//            if(root->val==a) printf("%d is an ancestor of %d.\n",a,b);
//            else printf("%d is an ancestor of %d.\n",b,a);
//        }
    }
}